home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / BBS / TAG2MAX.ZIP / USERCNV.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-10  |  6.8 KB  |  252 lines

  1. // usercnv.cpp
  2. // TAG 2.7x to Maximus 3.1 User Record Conversion
  3. // 02/10/96 - Version 1.0
  4. // (C) Copyright 1996, TranStar Technologies - All Rights Reserved
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <malloc.h>
  10. #pragma pack(1)
  11. #include "\bbsdev\tag.h"
  12. #include "max.h"
  13. #pragma pack()
  14. #include <math.h>
  15. #include <share.h>
  16.  
  17. #define TRUE    1
  18. #define FALSE   0
  19.  
  20. typedef unsigned short WORD;
  21. typedef unsigned char BYTE;
  22.  
  23. FILE *instream, *outstream;
  24. UserRec Urec;
  25. struct _usr MaxUser;
  26. short month, day, year;
  27. double tp6_to_double(const unsigned char *tp6);
  28.  
  29. void __pascal pas2c(char *source, char *dest);
  30. void ConvertRecord();
  31. void ConvertDate(WORD adate);
  32. void ConvertAR();
  33.  
  34. void main(int argc, char **argv)
  35. {
  36.     WORD count = 0;
  37.  
  38.     printf("USERCNV 1.0 - Tag to Maximus User Record Converter\n");
  39.     printf("(C) Copyright 1996, TranStar Technologies - All Rights Reserved\n\n");
  40.  
  41.     if (argc!=3) {
  42.         printf("Usage: USERCNV Tag-User.LST  Max-Users.BBS\n");
  43.         exit(0);
  44.     }
  45.     if ((instream = _fsopen(argv[1], "rb", _SH_DENYNO)) == NULL) {
  46.         printf("Cannot open %s\n", argv[1]);
  47.         exit(0);
  48.     }
  49.     if ((outstream = fopen(argv[2], "wb")) == NULL) {
  50.         printf("Cannot open %s\n", argv[2]);
  51.         fclose(instream);
  52.         exit(0);
  53.     }
  54.  
  55.     // For every tag user make the conversion. If the user number is 0, then the record has
  56.     // been deleted. In making the conversion, the AR flags will correspond more or less to
  57.     // the Maximus flags. Conversions must be made for certain TAG variables which use the
  58.     // non-standard Pascal Real field (download counts and the like).
  59.     
  60.     while(!feof(instream)) {
  61.         if (fread(&Urec, sizeof(UserRec), 1, instream) !=1) break;
  62.         if (Urec.UserNum==0) continue;    // deleted record
  63.         ConvertRecord();
  64.         count++;
  65.     }
  66.     fclose(instream);
  67.     fclose(outstream);
  68.     printf("\n%u User Records were converted.\n", count);
  69. }
  70.  
  71.  
  72. void __pascal pas2c(char *source, char *dest)
  73. {
  74.     short slen;
  75.     char *p;
  76.  
  77.     p = source;
  78.     slen = *p;
  79.     p++;
  80.     memcpy(dest, p, slen);
  81.     dest[slen] = 0;
  82. }
  83.  
  84.  
  85. void ConvertRecord()
  86. {
  87.     char tmp[132];
  88.     double val;
  89.  
  90.     pas2c((char *)Urec.Uname, tmp); tmp[21] = 0;
  91.     strcpy((char *)MaxUser.alias, tmp);
  92.     printf("User %3d: %s\n", Urec.UserNum, (char *)MaxUser.alias);
  93.     pas2c((char *)Urec.Rname, (char *)MaxUser.name);
  94.     pas2c((char *)Urec.CityState, (char *)MaxUser.city);
  95.     pas2c((char *)Urec.Phone, (char *)MaxUser.phone);
  96.     pas2c((char *)Urec.PW, tmp); tmp[16] = 0;
  97.     strcpy((char *)MaxUser.pwd, tmp);
  98.     MaxUser.times = Urec.NumCalls;
  99.     MaxUser.help = 0;
  100.     MaxUser.group = 0;
  101.     MaxUser.video = (Urec.Flags.Ansi) ? GRAPH_ANSI : GRAPH_TTY;
  102.     MaxUser.nulls = 0;
  103.     MaxUser.bits = 0;
  104.     if (Urec.Flags.OneKey) MaxUser.bits |= BITS_HOTKEYS;
  105.     if (Urec.ConfigFlags.DoNotDisturbUser) MaxUser.bits |= BITS_NOTAVAIL;
  106.     MaxUser.bits |= BITS_FSR;
  107.     if (Urec.Flags.Rchat) MaxUser.bits |= BITS_NERD;
  108.     MaxUser.bits |= BITS_TABS;
  109.  
  110.     ConvertDate(Urec.Bday);
  111.     MaxUser.dob_year = (WORD)year;
  112.     MaxUser.dob_month = (BYTE)month;
  113.     MaxUser.dob_day = (BYTE)day;
  114.     MaxUser.bits2 = 0;
  115.     MaxUser.bits2 |= BITS2_IBMCHARS;
  116.     MaxUser.bits2 |= BITS2_MORE;
  117.     if (Urec.Flags.Ansi) MaxUser.bits2 |= BITS2_RSVD2;
  118.     if (Urec.Flags.ClsChar) MaxUser.bits2 |= BITS2_CLS;
  119.     MaxUser.bits2 |= BITS2_CONFIGURED;
  120.  
  121.     // MaxUser.max2priv =
  122.     MaxUser.dataphone[0] = 0;
  123.     MaxUser.time = 0;
  124.     // MaxUser.delflag =
  125.     MaxUser.msgs_posted = Urec.PrivPost + Urec.PubPost + Urec.FeedBack;
  126.     // MaxUser.msgs_read =
  127.     MaxUser.width = Urec.Colms;
  128.     MaxUser.len = Urec.Lines;
  129.     MaxUser.credit = Urec.Credit;
  130.     MaxUser.debit = Urec.Debit;
  131.     // MaxUser.xp_priv =
  132.  
  133.     // MaxUser.xp_date
  134.     // MaxUser.xp_mins =
  135.     // MaxUser.xp_flag =
  136.     MaxUser.sex = (Urec.Gender == 'M') ? SEX_MALE : SEX_FEMALE;
  137.     // MaxUser.ludate
  138.  
  139.     // Convert TAG AR flags to Maximus XKeys
  140.     ConvertAR();
  141.  
  142.     MaxUser.struct_len = sizeof(struct _usr) / 20;
  143.     MaxUser.lang = 0;
  144.     // MaxUser.def_proto =
  145.  
  146.     // val = tp6_to_double((BYTE *)Urec.UlK);
  147.     MaxUser.up = 0L;
  148.     val = tp6_to_double((BYTE *)Urec.Dlk);
  149.     MaxUser.down = (dword)val;
  150.  
  151.     // MaxUser.downtoday =
  152.     MaxUser.call = 0;
  153.     // MaxUser.compress =
  154.     // MaxUser.df_save =
  155.     // MaxUser.extra =
  156.  
  157.     ConvertDate(Urec.FirstOn);
  158.     MaxUser.date_1stcall.msg_st.date.mo = month;
  159.     MaxUser.date_1stcall.msg_st.date.da = day;
  160.     MaxUser.date_1stcall.msg_st.date.yr = year + 20;
  161.     MaxUser.date_1stcall.dos_st.time = 0;
  162.  
  163.     MaxUser.date_pwd_chg.dos_st.date = MaxUser.date_1stcall.dos_st.date;
  164.     MaxUser.date_pwd_chg.dos_st.time = 0;
  165.  
  166.     MaxUser.nup = (dword)Urec.NumUL;
  167.     MaxUser.ndown = (dword)Urec.NumDL;
  168.     MaxUser.ndowntoday = 0;
  169.     MaxUser.point_credit = (dword)Urec.Points;
  170.     MaxUser.point_debit = 0;
  171.  
  172.     MaxUser.priv = (WORD)Urec.SL;
  173.  
  174.     strcpy((char *)MaxUser.msg, "1");
  175.     strcpy((char *)MaxUser.files, "1");
  176.  
  177.     fwrite(&MaxUser, sizeof(struct _usr), 1, outstream);
  178.     memset(&MaxUser, 0, sizeof(struct _usr));
  179. }
  180.  
  181. void ConvertDate(WORD adate)
  182. {
  183.     day = (short)(adate & 31);
  184.     adate >>= 5;
  185.     month = (short)(adate & 15);
  186.     adate >>= 4;
  187.     year = (short)adate;
  188. }
  189.  
  190. void ConvertAR()
  191. {
  192.     BYTE *p, arstring[40], val, tmp[40];
  193.     short i, j, k = 0;
  194.  
  195.     p = (BYTE *)&Urec.Ar[0];
  196.     for (j = 0; j<4; j++) {
  197.         val = *p;
  198.         for (i = 0; i<8; i++) {
  199.             if (val & 1) arstring[k] = 'X';
  200.             else arstring[k] = ' ';
  201.             val >>= 1;
  202.             k++;
  203.         }
  204.         p++;
  205.     }
  206.     arstring[k] = 0;
  207.  
  208.     p = (BYTE *)&MaxUser.xkeys;
  209.     p++;
  210.     k = 1;
  211.     for(i = 0; i<3; i++) {
  212.         val = 1;
  213.         for (j = 0; j<8; j++) {
  214.             if (arstring[k] == 'X') *p |= val;
  215.             val <<= 1;
  216.             k++;
  217.         }
  218.         p++;
  219.     }
  220.  
  221.     p = (BYTE *)&MaxUser.xkeys;
  222.     val = 1;
  223.     for (i = 0; i<3; i++) {
  224.         if (arstring[k] == 'X') *p |= val;
  225.         val <<= 1;
  226.         k++;
  227.     }
  228. }
  229.  
  230. #pragma pack(1)
  231.  
  232. double tp6_to_double(const unsigned char *tp6)
  233. {
  234.       struct {
  235.             unsigned char be  ;     /* biased exponent           */
  236.             unsigned int  v1  ;     /* lower 16 bits of mantissa */
  237.             unsigned int  v2  ;     /* next  16 bits of mantissa */
  238.             unsigned int  v3:7;     /* upper  7 bits of mantissa */
  239.             unsigned int  s :1;     /* sign bit                  */
  240.       } real;
  241.  
  242.       memcpy (&real, tp6, 6);
  243.       if (real.be == 0)
  244.             return 0.0;
  245.       return (((((128 +real.v3) * 65536.0) + real.v2) * 65536.0 + real.v1)
  246. *
  247.             ldexp ((real.s? -1.0: 1.0), real.be - (129+39)));
  248. }
  249.  
  250. #pragma pack()
  251.  
  252.